﻿using System;
using System.Collections.Generic;

namespace TicketSellingServer
{
    internal static class ReservationsDatabase
    {
        private static int currentReservationId = 100;

        private static readonly Dictionary<string, ReservedFlight> reservations = new Dictionary<string, ReservedFlight>();

        public static string Reserve(string flightId, DateTime date)
        {
            var reservationId = (currentReservationId++).ToString();

            reservations[reservationId] = new ReservedFlight
            {
                FlightId = flightId,
                Date = date,
            };

            return reservationId;
        }

        public static ReservedFlight Cancel(string reservationId)
        {
            ReservedFlight reservedFlight;
            if (reservations.TryGetValue(reservationId, out reservedFlight))
            {
                reservations.Remove(reservationId);
                return reservedFlight;
            }

            return null;
        }
    }
}
